package org.example.gui.panel;

import org.example.gui.widget.BudgetTablePanel;
import org.example.util.ChartUtil;
import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.PieChart;
import org.knowm.xchart.XChartPanel;

import javax.swing.*;
import java.awt.*;


public class StatisticPanel extends WorkingPanel {
    public static StatisticPanel instance = new StatisticPanel();
    JTabbedPane tabbedPane = new JTabbedPane();

    private StatisticPanel() {
        this.setLayout(new BorderLayout());
        this.add(tabbedPane, BorderLayout.CENTER);
    }


    @Override
    public void updateData() {
        tabbedPane.removeAll();
        PieChart pieChart = ChartUtil.getPieChart();
        CategoryChart categoryChart = ChartUtil.getCategoryChart();
        JPanel piePanel = new XChartPanel<>(pieChart);
        JPanel categoryPanel = new XChartPanel<>(categoryChart);
        tabbedPane.add("扇形图", piePanel);
        tabbedPane.add("柱状图", categoryPanel);
        tabbedPane.add("预算表", BudgetTablePanel.instance);
        BudgetTablePanel.instance.updateData();
    }

    @Override
    public void addListener() {

    }
}
